//
//  SZNavigationController.m
//  Weibo
//
//  Created by Zahi on 2017/7/23.
//  Copyright © 2017年 Zahi. All rights reserved.
//

#import "SZNavigationController.h"

@interface SZNavigationController ()

@end

@implementation SZNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}

#pragma mark - 重写pushView
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    [super pushViewController:viewController animated:animated];
    
    
    if (self.viewControllers.count > 1) { //忽略根控制器
        
        NSString *title;
        if (self.viewControllers.count == 2) { // 第二级控制器
            title = self.viewControllers.firstObject.title;
        } else {
            
            title = @"返回";
        }
        
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithTitle:title image:@"navigationbar_back_withtext" target:self action:@selector(backItemAction)];
        
        viewController.navigationItem.title = [NSString stringWithFormat:@"当前第%ld级控制器",self.viewControllers.count];
    }
    
    
    
}

#pragma mark - 监听返回按钮的点击
- (void)backItemAction
{
    [self popViewControllerAnimated:YES];
}

@end
